package com.wise.webservicecxf.config;

import com.wise.webservicecxf.server.UserService;
import com.wise.webservicecxf.server.impl.UserServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * 服务发布类编写
 * 在测试发布服务的时候，你在浏览器中输入的url地址应该是：http://localhost:8080/你的工程名/service/user?wsdl；
 */
@Configuration
public class WebServiceConfig {

    @Bean(name = "cxfDispatchServlet")
    /**
     * 方法名不要默认定义为dispatcherServlet,和springMVC的dispatcherServlet冲突
     */
    public ServletRegistrationBean dispatcherServlet(){
        //发布服务名称
        return new ServletRegistrationBean(new CXFServlet(),"/service/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus(){
        return new SpringBus();
    }

    @Bean
    public UserService userService(){
        return new UserServiceImpl();
    }

    @Bean
    public Endpoint endpoint(){
        EndpointImpl endpoint = new EndpointImpl(springBus(), userService());
        endpoint.publish("/user");
        return endpoint;
    }
}
